package com.gh.controller.admin;

import com.gh.common.result.R;
import com.gh.entity.BorrowInfo;
import com.gh.service.BorrowInfoService;
import com.gh.vo.BorrowInfoApprovalVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.text.ParseException;
import java.util.List;
import java.util.Map;

/**
 * @Author Eric
 * @Date 2021/10/10 22:38
 * @Version 1.0
 */
@Api(tags = "借款信息管理接口")
@RestController
@Slf4j
@RequestMapping("/admin/core/borrowInfo")
@RequiredArgsConstructor
public class AdminBorrowInfoController {

    private final BorrowInfoService borrowInfoService;

    @ApiOperation("借款信息列表")
    @GetMapping("/list")
    public R list() {
        List<BorrowInfo> borrowInfoList = borrowInfoService.selectList();
        return R.ok().data("borrowInfoList", borrowInfoList);
    }

    @ApiOperation("获取借款信息详情")
    @GetMapping("/show/{id}")
    public R show(@ApiParam(value = "借款详情id", required = true)
                  @PathVariable Long id) {
        Map<String, Object> borrowInfoDetail = borrowInfoService.getBorrowInfoDetail(id);
        return R.ok().data("borrowInfoDetail", borrowInfoDetail);
    }

    @ApiOperation("借款信息审批")
    @PostMapping("/approval")
    public R approval(@RequestBody BorrowInfoApprovalVo borrowInfoApprovalVo) throws ParseException {
        borrowInfoService.approval(borrowInfoApprovalVo);
        return R.ok().message("审核完成");
    }
}
